package jeopardy.server;

import java.io.File;
import java.io.FileInputStream;
import java.nio.charset.Charset;
import java.util.Properties;

import org.apache.log4j.Logger;

public class ServerConsts {
	private static Logger log = Logger.getLogger(ServerConsts.class);
	
	static{
		try{
			File f = new File("resources/jeopardy.properties");
			FileInputStream fis = new FileInputStream(f);
			
			Properties props = new Properties();
			props.load(fis);
			
			fis.close();
			
			GAME_CONN_TIMEOUT_MILLI = Integer.parseInt(props.getProperty("GAME_CONN_TIMEOUT_MILLI", "30000"));
			USERACCOUNT_MD_ALG = props.getProperty("USERACCOUNT_MD_ALG", "SHA-256");
			SSL_LOCAL_KEYSTORE_TYPE = props.getProperty("SSL_LOCAL_KEYSTORE_TYPE", "JKS");
			SSL_KEYMANAGER_ALGORITHM = props.getProperty("SSL_KEYMANAGER_ALGORITHM", "SunX509");
			SSL_VERSION = props.getProperty("SSL_VERSION", "SSLV3");
			UAM_CORETHREADS = Integer.parseInt(props.getProperty("UAM_CORETHREADS", "3"));
			UAM_POOLSIZE = Integer.parseInt(props.getProperty("UAM_POOLSIZE", "10"));
			UAM_THREAD_KEEPALIVE_MILLI = Integer.parseInt(props.getProperty("UAM_THREAD_KEEPALIVE_MILLI", "0"));
			UAM_MAX_WAITING_JOBS = Integer.parseInt(props.getProperty("UAM_MAX_WAITING_JOBS", "32"));
			USERACCOUNT_PASS_SALT = props.getProperty("USERACCOUNT_PASS_SALT", "JEOPARDY SALT!").getBytes(Charset.forName("UTF-8"));
			UAM_CONN_KEEPALIVE_MILLI = Integer.parseInt(props.getProperty("UAM_CONN_KEEPALIVE_MILLI", "10000"));
			GM_CORETHREADS = Integer.parseInt(props.getProperty("GM_CORETHREADS", "2"));
			GM_POOLSIZE = Integer.parseInt(props.getProperty("GM_POOLSIZE", "10"));
			GM_THREAD_KEEPALIVE_MILLI = Integer.parseInt(props.getProperty("GM_THREAD_KEEPALIVE_MILLI", "0"));
			GM_MAX_WAITING_JOBS = Integer.parseInt(props.getProperty("GM_MAX_WAITING_JOBS", "32"));
			GM_CONN_TIMEOUT_MILLI = Integer.parseInt(props.getProperty("GM_CONN_TIMEOUT_MILLI", "5000"));
			MAX_CONCURRENT_GAMES = Integer.parseInt(props.getProperty("MAX_CONCURRENT_GAMES", "1000"));
			MAX_USER_WAIT_TIME_MILLIS = Long.parseLong(props.getProperty("MAX_USER_WAIT_TIME_MILLIS", "300000") );
			ROUNDS_PER_GAME = Integer.parseInt(props.getProperty("ROUNDS_PER_GAME", "10"));
			GAME_START_WAIT_MILLI = Integer.parseInt(props.getProperty("GAME_START_WAIT_MILLI", "5000"));
			SM_CORETHREADS = Integer.parseInt(props.getProperty("SM_CORETHREADS", "3"));
			SM_POOLSIZE = Integer.parseInt(props.getProperty("SM_POOLSIZE", "10"));
			SM_THREAD_KEEPALIVE_MILLI = Long.parseLong(props.getProperty("SM_THREAD_KEEPALIVE_MILLI", "0"));
			SM_MAX_WAITING_JOBS = Integer.parseInt(props.getProperty("SM_MAX_WAITING_JOBS", "64"));
			SM_CONN_KEEPALIVE_MILLI = Integer.parseInt(props.getProperty("SM_CONN_KEEPALIVE_MILLI", "5000"));
			ROUND_TIME = Long.parseLong(props.getProperty("ROUND_TIME", "60000"));
			POINTS_PER_ROUND = Integer.parseInt(props.getProperty("POINTS_PER_ROUND", "10"));
		}catch(Exception e){
			log.info("error reading properties");
			log.debug("error reading properties", e);
		}
	}
	
	public static String USERACCOUNT_MD_ALG;
	public static String SSL_LOCAL_KEYSTORE_TYPE;
	public static String SSL_KEYMANAGER_ALGORITHM;
	public static String SSL_VERSION;
	public static int UAM_CORETHREADS;
	public static int UAM_POOLSIZE;
	public static int UAM_THREAD_KEEPALIVE_MILLI;
	public static int UAM_MAX_WAITING_JOBS;
	public static byte[] USERACCOUNT_PASS_SALT;
	public static int UAM_CONN_KEEPALIVE_MILLI;
	public static int GM_CORETHREADS;
	public static int GM_POOLSIZE;
	public static int GM_THREAD_KEEPALIVE_MILLI;
	public static int GM_MAX_WAITING_JOBS;
	public static int GM_CONN_TIMEOUT_MILLI;
	public static int MAX_CONCURRENT_GAMES;
	public static int GAME_CONN_TIMEOUT_MILLI;
	public static long MAX_USER_WAIT_TIME_MILLIS;
	public static int ROUNDS_PER_GAME;
	public static long GAME_START_WAIT_MILLI;
	public static int SM_CORETHREADS;
	public static int SM_POOLSIZE;
	public static long SM_THREAD_KEEPALIVE_MILLI;
	public static int SM_MAX_WAITING_JOBS;
	public static int SM_CONN_KEEPALIVE_MILLI;
	public static long ROUND_TIME;
	public static int POINTS_PER_ROUND;
}
